﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace geraAplicacao
{
    public partial class frmMDIPrincipal : Form
    {
        private int childFormNumber = 0;

        public frmMDIPrincipal()
        {
            InitializeComponent();
        }

        private void ShowNewForm(object sender, EventArgs e)
        {
            //Form childForm = new Form();
            //childForm.MdiParent = this;
            //childForm.Text = "Window " + childFormNumber++;
            //childForm.Show();
            frmModelo2 frmTemp = new frmModelo2();
            frmTemp.MdiParent = this;
            frmTemp.Text = "*Novo Modelo";
            frmTemp.WindowState = FormWindowState.Maximized;
            frmTemp.Show();
        }
        private string psPastaTrabalho = "";
        private void OpenFile(object sender, EventArgs e)
        {

            string FileName="";
            //FileName = AppDomain.CurrentDomain.BaseDirectory + "projetoArmarioDigital3.xml";

            OpenFileDialog openFileDialog = new OpenFileDialog();
            //openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            openFileDialog.Filter = "Plataform Independent Model (*.pim)|*.pim|All Files (*.*)|*.*";

            if (openFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                FileName = openFileDialog.FileName;
            }

            if(!String.IsNullOrEmpty( FileName))
            {
                frmModelo2 frmTemp = new frmModelo2(FileName);
                frmTemp.MdiParent = this;
                frmTemp.Text = FileName;
                frmTemp.WindowState = FormWindowState.Maximized;
                frmTemp.Show();
            }
        }

        private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            //saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            saveFileDialog.Filter = "Plataform Independent Model (*.pim)|*.pim|All Files (*.*)|*.*";
            if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string FileName = saveFileDialog.FileName;
                ((frmModelo2)this.ActiveMdiChild).save3(FileName);
            }
        }

        private void ExitToolsStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void CutToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void CopyToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void PasteToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void ToolBarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            toolStrip.Visible = toolBarToolStripMenuItem.Checked;
        }

        private void StatusBarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            statusStrip.Visible = statusBarToolStripMenuItem.Checked;
        }

        private void CascadeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.Cascade);
        }

        private void TileVerticalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileVertical);
        }

        private void TileHorizontalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileHorizontal);
        }

        private void ArrangeIconsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.ArrangeIcons);
        }

        private void CloseAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (Form childForm in MdiChildren)
            {
                childForm.Close();
            }
        }

        private void generateSourceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //try
            //{
                ((frmModelo2)this.ActiveMdiChild).generate();
            /*}
            catch (Exception ex)
            {
                MessageBox.Show("Não há um modelo aberto!"); 
            }*/
        }

        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            String FileName = ActiveMdiChild.Text;
            if (FileName.Equals("*Novo Modelo"))
            {
                SaveFileDialog saveFileDialog = new SaveFileDialog();
                //saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                saveFileDialog.Filter = "Plataform Independent Model (*.pim)|*.pim|All Files (*.*)|*.*";
                if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
                {
                    FileName = saveFileDialog.FileName;
                }
            }
            else {
            
            }
            ((frmModelo2)this.ActiveMdiChild).save3(FileName);
        }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            (new frmSobre()).ShowDialog(); 
        }
    }
}
